 <?php
/**
 * 通过传入参数的url判断是否为目录分类，从而获取子菜单
 *
 * @param string $url
 */
function get_subcate_byurl($url)
{
	$rs = strpos($url,"category");
	if($rs!==false)
	{
		preg_match("/\d+/i",$url,$matches);
		$cid = $matches[0];
		$cat_arr = array();
		$sql = "select * from ".$GLOBALS['ecs']->table('category')." where parent_id=".$cid." and is_show=1";
		$res = $GLOBALS['db']->getAll($sql);
		
		foreach($res as $idx => $row)
		{
			$cat_arr[$idx]['id']   = $row['cat_id'];
            $cat_arr[$idx]['name'] = $row['cat_name'];
            $cat_arr[$idx]['url']  = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
			$cat_arr[$idx]['children'] = get_clild_list($row['cat_id']);
		}

		return $cat_arr;
	}
	else 
	{
		return false;
	}
}
/*
 * 热门分类树
 * @param int pid
 * @param int rec
 */
function get_hot_cat_tree($pid = 0, $rec=3)
{
     $arr=array();
     $sql="select c.* from ".$GLOBALS['ecs']->table('category')." as c left join ".$GLOBALS['ecs']->table('cat_recommend')." as rc on c.cat_id = rc.cat_id where rc.recommend_type=$rec and c.parent_id=$pid order by c.sort_order asc, c.cat_id asc";
	 $res=$GLOBALS['db']->getAll($sql);
	 foreach($res as  $row)
	 {
	    $arr[$row['cat_id']]['id']    = $row['cat_id']; 
		$arr[$row['cat_id']]['name']  = $row['cat_name']; 
		$arr[$row['cat_id']]['url']   = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
		$arr[$row['cat_id']]['chlid'] = get_hot_cat_tree($row['cat_id'],$rec);
	 }
	 return $arr;
}



function get_clild_list($pid)
{
   //开始获取子分类
    $sql_sub = "select * from ".$GLOBALS['ecs']->table('category')." where parent_id=".$pid." and is_show=1";

	$subres = $GLOBALS['db']->getAll($sql_sub);
	if($subres)
	{
		foreach ($subres as $sidx => $subrow)
		{
			$children[$sidx]['id']=$subrow['cat_id'];
			$children[$sidx]['name']=$subrow['cat_name'];
			$children[$sidx]['url']=build_uri('category', array('cid' => $subrow['cat_id']), $subrow['cat_name']);
		}
	}
	else 
	{
		$children = null;
	}
			
	return $children;
}



?>
</head>
<body>
<script type="text/javascript">
var process_request = "<?php echo $this->_var['lang']['process_request']; ?>";
var btn_buy = "<?php echo $this->_var['lang']['btn_buy']; ?>";
var is_cancel = "<?php echo $this->_var['lang']['is_cancel']; ?>";
var select_spe = "<?php echo $this->_var['lang']['select_spe']; ?>";
</script>
<div id="header">
  <div class="topnav">
  	<div class="tl fwhite fl">买酒就上酒香网</div>
    <div class="tr"> 
       
      <?php echo $this->smarty_insert_scripts(array('files'=>'transport.js,utils.js')); ?>
      <div id="ECS_MEMBERZONE"><?php 
$k = array (
  'name' => 'member_info',
);
echo $this->_echash . $k['name'] . '|' . serialize($k) . $this->_echash;
?></div>
       
          <?php if ($this->_var['navigator_list']['top']): ?>
          <ul>
            <?php $_from = $this->_var['navigator_list']['top']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'nav');$this->_foreach['nav_top_list'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['nav_top_list']['total'] > 0):
    foreach ($_from AS $this->_var['nav']):
        $this->_foreach['nav_top_list']['iteration']++;
?>
            <li> <a href="<?php echo $this->_var['nav']['url']; ?>" 
              <?php if ($this->_var['nav']['opennew'] == 1): ?> 
              target="_blank" 
              <?php endif; ?> 
              ><?php echo $this->_var['nav']['name']; ?></a> </li>
            <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
          </ul>
          <?php endif; ?> 
    </div>
  </div>
  <div class="header">
    <div class="logo"><a href="index.php"><img src="themes/jiuxian/images/logo.gif" alt="<?php echo $this->_var['page_title']; ?>" /></a></div>
    <div class="sear f_l">
      <form id="searchForm" name="searchForm" method="get" action="search.php" onSubmit="return checkSearchForm()" >
        <input name="keywords" type="text" id="keyword" onblur="javascript:if(this.value=='')this.value='<?php if ($this->_var['searchkeywords']): ?><?php $_from = $this->_var['searchkeywords']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'val');if (count($_from)):
    foreach ($_from AS $this->_var['val']):
?><?php echo $this->_var['val']; ?><?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?><?php endif; ?>'" 
onfocus="javascript:if(this.value=='<?php if ($this->_var['searchkeywords']): ?><?php $_from = $this->_var['searchkeywords']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'val');if (count($_from)):
    foreach ($_from AS $this->_var['val']):
?><?php echo $this->_var['val']; ?><?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?><?php endif; ?>')this.value='';" 
value="<?php echo htmlspecialchars($this->_var['search_keywords']); ?>" size="30" class="TextInput"/>
        <input name="imageField" type="submit" value="搜索" class="go"  />
      </form>
    </div>
    <div class="key f_l"> 
      <script type="text/javascript">
    
    <!--
    function checkSearchForm()
    {
        if(document.getElementById('keyword').value)
        {
			//s.keywords=document.getElementById('keyword').value;
			// by sean add for allyes 2011-04-04
            return true;
        }
        else
        {
            alert("<?php echo $this->_var['lang']['no_keywords']; ?>");
            return false;
        }
    }
    -->
    
    </script></div>
    <div class="tel400 fr"></div>
    <div class="zheng fr"></div>
  </div>
  <div class="searchbox block">
  	<div class="new"></div>
    <div class="hot"></div>
    <div class="menu"> <span class="R"></span>
      <dl>
      


        <div id="nav_home">

          <ul>
            
            <li <?php if ($this->_var['navigator_list']['config']['index'] == 1): ?> class="nav_home_ed" <?php else: ?> class="nav_home_we" <?php endif; ?> > <a href="index.php"><?php echo $this->_var['lang']['home']; ?></a><span></span> </li>
            
          </ul>
        </div>
        <div id="category_tree">
          <ul>
            
            <?php $_from = $this->_var['categories']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'cat');$this->_foreach['parent-cat'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['parent-cat']['total'] > 0):
    foreach ($_from AS $this->_var['cat']):
        $this->_foreach['parent-cat']['iteration']++;
?>
            <li onMouseOver="<?php if ($this->_var['cat']['cat_id']): ?>showMenu('c<?php echo $this->_foreach['parent-cat']['iteration']; ?>',1); this.className='sean';<?php endif; ?>"  onMouseOut="<?php if ($this->_var['cat']['cat_id']): ?>showMenu('c<?php echo $this->_foreach['parent-cat']['iteration']; ?>',0); this.className='';<?php endif; ?>" <?php if ($this->_var['cat']['id'] == $this->_var['cat_cur']): ?>id="cat_cur" <?php endif; ?> >
            <a <?php if ($this->_var['nav']['active'] == 1): ?>class="sean"<?php endif; ?> href="<?php echo $this->_var['cat']['url']; ?>" class="cat_a"><?php echo htmlspecialchars($this->_var['cat']['name']); ?></a> 
              <?php if ($this->_var['cat']['cat_id']): ?>
              <div id="c<?php echo $this->_foreach['parent-cat']['iteration']; ?>" class="children">
                <div class="conter clearfix"> 
                
                  <?php $_from = $this->_var['cat']['cat_id']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'child');$this->_foreach['cat_child'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['cat_child']['total'] > 0):
    foreach ($_from AS $this->_var['child']):
        $this->_foreach['cat_child']['iteration']++;
?> 
                  
                  
                  <a href="<?php echo $this->_var['child']['url']; ?>" class="ChildrenLi"><?php echo htmlspecialchars($this->_var['child']['name']); ?></a> 
                  
                  <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?> 
                </div>
              </div>
              <?php endif; ?> 
            </li>
            <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
          </ul>
        <script type="text/javascript">
			function $(element) {
			 return document.getElementById(element);
			}
			function showMenu(menuID,index) {
			 $(menuID).style.display=(index==0?"none":"block");
			}
        </script> 
        </div>
        
        
        <?php $_from = $this->_var['navigator_list']['middle']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'nav');$this->_foreach['nav_middle_list'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['nav_middle_list']['total'] > 0):
    foreach ($_from AS $this->_var['nav']):
        $this->_foreach['nav_middle_list']['iteration']++;
?>
        <div <?php if ($this->_var['nav']['active'] == 1): ?>class="nav_cur fl"<?php endif; ?> class="nav_bur fl"> <a href="<?php echo $this->_var['nav']['url']; ?>" <?php if ($this->_var['nav']['opennew'] == 1): ?>target="_blank" <?php endif; ?>><?php echo $this->_var['nav']['name']; ?></a><span></span>
        </div>
        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
        
        <div class="cart f_r">
          <div id="cartInfo"><?php 
$k = array (
  'name' => 'cart_info',
);
echo $this->_echash . $k['name'] . '|' . serialize($k) . $this->_echash;
?></div>
        </div>
      </dl>
    </div>
  </div>
</div>
